package com.chl.crc;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.TreeMap;
import java.util.zip.CRC32;

public class TestCrc {

	
	public static long calculateCRC(String filePath) throws IOException {
	    CRC32 crc = new CRC32();
	    try (InputStream inputStream = new BufferedInputStream(new FileInputStream(filePath))) {
	        byte[] buffer = new byte[8192]; // 8KB 缓冲区
	        int bytesRead;
	        while ((bytesRead = inputStream.read(buffer)) != -1) {
	            crc.update(buffer, 0, bytesRead);
	        }
	    }
	    return crc.getValue();
	}

	public static void main(String[] args) {
	    String filePath = "C:\\Users\\006006\\Desktop\\CRC\\image1.jpeg"; // 替换为你的文件路径
	    try {
	        long crcValue = calculateCRC(filePath);
	        System.out.println("CRC32: " + Long.toHexString(crcValue).toUpperCase());
	    } catch (IOException e) {
	        System.err.println("Error reading file: " + e.getMessage());
	    }
	    
	    
	    
	    filePath = "C:\\Users\\006006\\Desktop\\CRC\\image2.jpeg"; // 替换为你的文件路径
	    try {
	        long crcValue = calculateCRC(filePath);
	        System.out.println("CRC32: " + Long.toHexString(crcValue).toUpperCase());
	    } catch (IOException e) {
	        System.err.println("Error reading file: " + e.getMessage());
	    }
	    
	    
	    
	    
	    TreeMap<String,Integer> tmap = new TreeMap<String,Integer>(); 	    
	    
	    File ff = new File("C:\\Users\\006006\\Desktop\\CRC");
	    if(ff.isDirectory()) {
	    	File file[] = ff.listFiles();
	    	for(int i = 0 ; i < file.length ; i++) {
	    		
	    	}
	    }
	    
	}
	
	
	
	
	
	
	
	
}

